package trabajoISW2.presentation.shared;

import java.util.Iterator;

import trabajoISW2.domain.implementations.Book;
import trabajoISW2.domain.implementations.Publisher;

public class PublisherMapper {
	
	public static PublisherDTO createDTO (Publisher p){
		PublisherDTO dto = new PublisherDTO(p.getName(), null);
		Iterator<Book> it = p.getBooks().iterator();
		BookDTO bdto;
		Book b;
		while (it.hasNext()){
			b= it.next();
			bdto = BookMapper.createDTO(b);
			dto.getBooks().add(bdto);
		}
		return dto;
	}
	
	public static Publisher updateDomainObject (PublisherDTO dto){
		Publisher p = new Publisher (dto.getName(), null);
		Iterator<BookDTO> it = dto.getBooks().iterator();
		BookDTO bdto;
		Book b;
		while (it.hasNext()){
			bdto= it.next();
			b = BookMapper.updateDomainObject(bdto);
			p.addBook(b);
		}
		return p;
	}

}
